<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>引出问题</title>
		<!-- 引入react核心库 -->
		<script type="text/javascript" src="../js/react.js"></script>
		<!-- 引入react-dom，用于支持react操作DOM -->
		<script type="text/javascript" src="../js/react-dom.js"></script>
		<!-- 引入babel，用于解析jsx为js -->
		<script type="text/javascript" src="../js/babel.min.js"></script>
	</head>
	<body>
		<!-- 准备好一个容器 -->
		<div id="root"></div>
		
		<script type="text/babel">
			class Person extends React.Component{
				state = {persons:[
					{id:'001',name:'张三',age:18},
					{id:'002',name:'李四',age:19},
					{id:'003',name:'王五',age:20},
				]}
				render(){
					return(
						<div>
							<button onClick={this.addLiu}>添加一个老刘</button>	
							<ul>
								{
									this.state.persons.map((p,index)=>{
										return (
											<li key={index}>
												{p.name}-{p.age}
												<input type="text"/>
											</li>
										)
									})
								}
							</ul>
						</div>
					)
				}
				addLiu = ()=>{
					const {persons} = this.state
					const liu = {id:'004',name:'老刘',age:30}
					this.setState({persons:[liu,...persons]})
				}
			}
			ReactDOM.render(<Person/>,document.getElementById('root'))
		</script>
	</body>
</html>